import { updateSettlementPrice } from '@/api/order'
import { OrderAPIRequestParam } from '@/typings/api/order'
import { ref } from 'vue'

export default function (workIds: Array<string>) {
  // 表单
  const form = ref<OrderAPIRequestParam.UpdateSettlementPrice>({
    factorySettlementPrice: '0',
    networkSettlementPrice: '0',
    workIds,
  })

  // 更新加载
  const updateLoading = ref(false)

  /**
   * 更新方法
   */
  const update = async () => {
    updateLoading.value = true
    const res = await updateSettlementPrice(form.value)
    updateLoading.value = false
    return res.data as { code: number; message: string; data: object; success: boolean }
  }

  return {
    form,
    updateLoading,
    update,
  }
}
